﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.Drawing;

//using System.Runtime.CompilerServices;
using System.Runtime.Serialization;

namespace HA.Data.DisplayOptions2
{

  
    [Serializable ]
    public class ContourLineScalarBar : ContourEventProperty, IObjectDataHelper, ICloneable 
    {

        //注意 ：修改字段后 需要修改运算符重载

        public ContourLineScalarBar()
        { 
        

        }



        bool _isShowScalarBar = true ;
        /// <summary>
        /// 是否显示图例
        /// </summary>
        public bool IsShowScalarBar
        {
            get { return _isShowScalarBar; }
            set
            {
                if (_isShowScalarBar == value)
                {
                    return;
                }
                else
                {
                    _isShowScalarBar = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

        bool _isDragable = true;
        /// <summary>
        /// 是否允许拖动
        /// </summary>
        public bool IsDragable
        {
            get { return _isDragable; }
            set
            {
                if (_isDragable == value)
                {
                    return;
                }
                else
                {
                    _isDragable = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }




        int _width = 4;
        /// <summary>
        /// 图例宽度  占视口比例 百分比  100%为全部
        /// </summary>
        public int Width
        {
            get { return _width; }
            set
            {
                if (value <= 0 || value > 100)
                {
                    return;
                }

                if (_width == value)
                {
                    return;
                }
                else
                {
                    _width = value;
                    this.isNeedUpdateData = true;
                }

            }
        }



        int _height = 50;
        /// <summary>
        /// 图例高度     占视口比例 百分比  100%为全部
        /// </summary>
        public int Height
        {
            get { return _height; }
            set {
                if (value <= 0 || value > 100)
                {
                    return;
                }
                if (_height == value)
                {
                    return;
                }
                else
                {
                    _height = value;
                    this.isNeedUpdateData = true;
                }
 
            }
        }




        int _xToViewPortLeftUper = 0;
        /// <summary>
        /// 图例左上角距离视口左上角的位置  X   偏移量  百分比  100%为全部
        /// </summary>
        public int XToViewPortLeftUper
        {
            get { return _xToViewPortLeftUper; }
            set {
                if (value < 0 || value > 100)
                {
                    return;
                }

                if (_xToViewPortLeftUper == value)
                {
                    return;
                }
                else
                {
                    _xToViewPortLeftUper = value;
                    this.isNeedUpdateData = true;
                }
          
            
            }
        }



        int _yToViewPortLeftUper = 0;
        /// <summary>
        ///  图例左上角距离视口左上角的位置  Y   偏移量  百分比  100%为全部
        /// </summary>
        public int YToViewPortLeftUper
        {
            get { return _yToViewPortLeftUper; }
            set
            {
                if (value < 0 || value > 100)
                {
                    return;
                }
                if (_yToViewPortLeftUper == value)
                {
                    return;
                }
                else
                {
                    _yToViewPortLeftUper = value;
                    this.isNeedUpdateData = true;
                }

            }
        }











        string _title = "DataSet";
        /// <summary>
        /// 图例标题
        /// </summary>
        public string Title
        {
            get { return _title; }
            set
            {
                if (_title == value)
                {
                    return;
                }
                else
                {
                    _title = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }




        Color _titleColor = Color.Black;
       /// <summary>
       /// 图例标题颜色
       /// </summary>
        public Color TitleColor
        {
            get { return _titleColor; }
            set
            {
                if (_titleColor == value)
                {
                    return;
                }
                else
                {
                    _titleColor = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }



        int _titleFontSize = 10;
        /// <summary>
        /// 图例标题字体大小
        /// </summary>
        public int TitleFontSize
        {
            get { return _titleFontSize; }
            set
            {
                if (_titleFontSize == value)
                {
                    return;
                }
                else
                {
                    _titleFontSize = value;
                    this.IsNeedUpdateData = true;
                }
                if (_titleFontSize <= 0)
                {
                    _titleFontSize = 1;
                }
            }
        }


        Color _labelColor = Color.Black;
        /// <summary>
        /// 图例文本颜色
        /// </summary>
        public Color LabelColor
        {
            get { return _labelColor; }
            set
            {
                if (_labelColor == value)
                {
                    return;
                }
                else
                {
                    _labelColor = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

        int _labelFontSize = 10;
        /// <summary>
        /// 图例文本字体
        /// </summary>
        public int LabelFontSize
        {
            get { return _labelFontSize; }
            set
            {
                if (_labelFontSize == value)
                {
                    return;
                }
                else
                {
                    _labelFontSize = value;
                    this.IsNeedUpdateData = true;
                }
                if (_labelFontSize <= 0)
                {
                    _labelFontSize = 1;
                }
            }
        }


        #region 运算符重载


        public static bool operator ==(ContourLineScalarBar sp1, ContourLineScalarBar sp2)
        {

            if ((object)sp1 == null && (object)sp2 == null)
            {
                return true;
            }

            if (((object)sp1 == null && (object)sp2 != null) || ((object)sp1 != null && (object)sp2 == null))
            {
                return false;
            }

            if (sp1 != null && sp2 != null)
            {

                if (sp1 ._isDragable !=sp2 ._isDragable )
                {
                    return false;
                }



                if (sp1._width != sp2._width)
                {
                    return false;
                }

                if (sp1._height != sp2._height)
                {
                    return false;
                }
                if (sp1._xToViewPortLeftUper != sp2._xToViewPortLeftUper)
                {
                    return false;
                }
                if (sp1.YToViewPortLeftUper != sp2.YToViewPortLeftUper)
                {
                    return false;
                }




                if (sp1 ._title !=sp2._title )
                {
                    return false;
                }
                if (sp2._isShowScalarBar != sp1._isShowScalarBar)
                {
                    return false;
                }


                if (sp2 ._titleColor !=sp1 ._titleColor )
                {
                    return false;
                }
                if (sp1 ._titleFontSize !=sp2 ._titleFontSize )
                {
                    return false;
                }


                if (sp2 ._labelColor !=sp1 ._labelColor )
                {
                    return false;
                }
                if (sp1 ._labelFontSize !=sp2 ._labelFontSize )
                {
                    return false;
                }


                //if (sp1._fontSize != sp2._fontSize)
                //{
                //    return false;
                //}



                //if (sp2._labelFormat != sp1.LabelFormat)
                //{
                //    return false;
                //}



            }




            return true;
        }

        public static bool operator !=(ContourLineScalarBar sp1, ContourLineScalarBar sp2)
        {
            return (!(sp1 == sp2));

        }


        #endregion




        #region IObjectDataHelper 成员

        public void ResetDataAndTriggerEvent(object obj)
        {



            if (obj == null)
            {
                return;

            }
            ContourLineScalarBar doContour = (ContourLineScalarBar)obj;

            //运算符重载   其根本还是遍历类中的所有字段进行了比较  
            if (doContour.IsDataChanged() == false)
            {
                return;
            }


            //更新副本数据到源数据   7个字段

            List<string> ScalarBar = new List<string>();

            if (_isShowScalarBar !=doContour ._isShowScalarBar )
            {
                 _isShowScalarBar = doContour._isShowScalarBar;

                 ScalarBar.Add(ScalarBarChangedType.ScalarBarSetup.ToString());

            }


            if (IsDragable !=doContour .IsDragable )
            {
                 _isDragable = doContour._isDragable;

                 //ScalarBar.Add(ScalarBarChangedType.ScalarBarSetup.ToString());//界面不提供对应的接口，需求不需要该功能，暂时去掉，不触发事件

            }





            if (Width !=doContour .Width )
            {
                _width = doContour._width;
                //ScalarBar.Add(ScalarBarChangedType .ScalarBarSetup .ToString ());//界面不提供对应的接口，需求不需要该功能，暂时去掉，不触发事件
            }

            if (Height !=doContour ._height  )
            {
                _height = doContour._height;
                //ScalarBar.Add(ScalarBarChangedType .ScalarBarSetup .ToString ());//界面不提供对应的接口，需求不需要该功能，暂时去掉，不触发事件
            }
            if ( XToViewPortLeftUper  !=doContour . XToViewPortLeftUper  )
            {

                _xToViewPortLeftUper = doContour._xToViewPortLeftUper;
                //ScalarBar.Add(ScalarBarChangedType .ScalarBarSetup .ToString ());//界面不提供对应的接口，需求不需要该功能，暂时去掉，不触发事件

            }

            if (YToViewPortLeftUper != doContour.YToViewPortLeftUper)
            {
                _yToViewPortLeftUper = doContour._yToViewPortLeftUper;
                //ScalarBar.Add(ScalarBarChangedType .ScalarBarSetup .ToString ());//界面不提供对应的接口，需求不需要该功能，暂时去掉，不触发事件
            }








            if (_title !=doContour ._title )
            {
                 _title = doContour._title;

                 //ScalarBar.Add(ScalarBarChangedType.ScalarBarSetup.ToString());//界面不提供对应的接口，需求不需要该功能，暂时去掉，不触发事件
            }


            if (_titleColor !=doContour ._titleColor )
            {
                 _titleColor = doContour._titleColor;

                //ScalarBar.Add(ScalarBarChangedType.ScalarBarSetup.ToString());//界面不提供对应的接口，需求不需要该功能，暂时去掉，不触发事件
            }

            if (_titleFontSize != doContour._titleFontSize)
            {
                _titleFontSize = doContour._titleFontSize;

                //ScalarBar.Add(ScalarBarChangedType.ScalarBarSetup.ToString());//界面不提供对应的接口，需求不需要该功能，暂时去掉，不触发事件
            }

            if (_labelColor != doContour._labelColor)
            {
                _labelColor = doContour._labelColor;

                ScalarBar.Add(ScalarBarChangedType.ScalarBarSetup.ToString());
            }

            if (_labelFontSize !=doContour ._labelFontSize )
            {
                 _labelFontSize = doContour._labelFontSize;

                 ScalarBar.Add(ScalarBarChangedType.ScalarBarSetup.ToString());
            }


            if (ScalarBar.Count >0)
            {
                ScalarBar.Clear();

                ScalarBar.Add(ScalarBarChangedType.ScalarBarSetup.ToString());
            }


            if (ScalarBar.Count > 0)
            {
                this.AskContourSetupChanged(new ContourSetupChangedEventArgs(this, ContourSetupChangedType.ScalarBar, ScalarBar));

                //throw new NotImplementedException();
            }



            //throw new NotImplementedException();
        }

        public bool IsDataChanged()
        {


            if (this == null)
            {
                return false;
            }
            if (this.IsNeedUpdateData == true)
            {
                return true;
            }
            else
            {

                return false;
            }




            //throw new NotImplementedException();
        }

        #endregion

        #region ICloneable 成员

        public object Clone()
        {


            ContourLineScalarBar obj = (ContourLineScalarBar)this.MemberwiseClone();



            return  obj;


            //throw new NotImplementedException();
        }

        #endregion


        #region 反序机制

        [OnDeserializing]
        public void OnDeserializing(StreamingContext context)
        {


            if (this._width ==0)
            {
                this._width = 4;
            }
            if (this._height ==0)
            {
                this._height = 50;
            }
        
        }


        #endregion





    }
}
